/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source 
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.  
 */

package jdbcmanager.swing;

import java.util.Enumeration;

import javax.swing.*;

/**
 * A Popup Manu that can be initialised using instances of <code>JActionSet</code> class.
 *
 * @author Francisco Morero Peyrona
 */

public class JxPopupMenu extends JPopupMenu
{
   /**
    * Zero argument constructor
    */
   public JxPopupMenu()
   {
      this( null );   
   }
   
   /**
    * Constructor
    *
    * @param as
    */
   public JxPopupMenu( JActionSet as )
   {
      if( as != null )
         add( as );
   }

   /**
    * Add all Actions passed creating a new button per each action
    */
   public void add( JActionSet as )
   {
      for( Enumeration e = as.actions(); e.hasMoreElements(); )
      {
         Object action = e.nextElement();

         if( action == JActionSet.SEPARATOR )
            addSeparator();
         else
            add( new JMenuItem( (AbstractAction) action ) );
      }
   }

   /**
    * Add one JMenuItem using the passed Action
    *
    * @param act
    */
   public void add( AbstractAction act )
   {
      add( new JMenuItem( act ) );
   }
}